

import java.sql.Connection;
import java.sql.DriverManager;

import javax.swing.JOptionPane;

import java.sql.*;


public class Connect {
    private static Connect con = new Connect();
    public Connect() {
        try {
            java.lang.Class.forName("com.mysql.cj.jdbc.Driver");
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Database cannot be loaded"+e.getMessage());
        }
    }
    public static Connection getConn()
    {
        try {
            Connection conn = null;
            String ur1 = "jdbc:mysql://localhost:3306/SmartHomeG7";
            String username = "root";
            String password = "123456";
            conn = DriverManager.getConnection( ur1, username, password);
            //   JOptionPane.showMessageDialog(null, "Database is connected successfully! " );
            return conn;
        }
        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, "Database cannot be connected! " + e.getMessage());
            return null;
        }
    }
}